<template>
	<view>
		<TopNav title="库存记录"></TopNav>
		<SearchMenu @search="handleSearch" @reset="handleReset">
			<template v-slot:search>
				<van-cell title="仓库名称">
					<van-field v-model="queryParams.warehouseName" placeholder="输入仓库名称查询" :border="false"
						input-align="right" class="padding-none" />
				</van-cell>
				<van-cell title="产品名称">
					<van-field v-model="queryParams.productName" placeholder="输入产品名称查询" :border="false"
						input-align="right" class="padding-none" />
				</van-cell>
				<!-- <van-cell title="产品类型" :value="queryParams.productTypeDictName || '选择产品类型'" is-link>
				</van-cell>
				<van-cell title="操作类型" :value="queryParams.bizType || '选择操作类型'" is-link>
				</van-cell> -->
			</template>
		</SearchMenu>

		<view class="cu-card case">
			<view class="cu-item shadow padding" v-for="item in list" :key="item.id" @click="handleToDetail(item)">
				<view class="flex justify-between align-center">
					<view class="full-width">
						<view class="flex align-baseline justify-between ">
							<u-tag :text="item.bizType" plain plainFill :type="item.bizType==='入库'?'success':'primary'"
								size="mini"> </u-tag>
							<view class="text-left full-width overflow-hidden text-cut">
								<text class="text-bold text-lg padding-left">{{item.productName || '-'}}</text>
								<text>（{{item.productTypeName || '-'}}）</text>
							</view>
							<view class="shrink-0">
								<text class="text-bold">{{item.quantity}}</text>
								<text class="text-sm">{{item.quantityUnit}}</text>
							</view>
						</view>
						<view class="flex justify-between padding-top-xs">
							<view class="basis-df text-left">
								<text class="text-gray text-width">规格：</text>
								<text>{{item.productSpecifications || '0'}}{{item.productSpecificationsUnit || '-'}}</text>
							</view>
							<view class="basis-df text-left">
								<text class="text-gray text-width">库存：</text>
								<text>{{item.stock || '0'}}{{item.stockUnit || '-'}}</text>
							</view>
						</view>
						<view class="">
							<text class="text-gray text-width">时间：</text>
							<text>{{item.time || '-'}}</text>
						</view>
					</view>
					<view class="padding-left shrink-0 text-center">
						<view class="padding-xs shrink-0">
							<image :src="baseUrl + item.createUserAvatar" mode="widthFix"
								class="cu-avatar sm radius bg-transparent">
							</image>
							<view class="text-sm">{{item.createUsername || '-'}}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<u-loadmore :status="loadStatus" @loadmore="getMoreList" v-if="list.length" />
		<van-transition name="fade-up">
			<van-empty description="暂无数据" v-if="!list.length" />
		</van-transition>
	</view>
</template>

<script>
	import {
		listInventory as list
	} from "@/api/work/products-inventory"
	import mixins from "@/mixins"
	import {
		getDicts
	} from "@/api/system/dict";
	export default {
		mixins: [mixins],
		data() {
			return {
				baseUrl: getApp().globalData.config.baseUrl,
				list: [],
				loadStatus: 'loadmore',
				queryParams: {
					startDate: '',
					endDate: '',
					warehouseName: '',
					productName:'',
					pageSize: 10,
					pageNum: 1
				},

			};
		},
		onShow() {
			this.getList()
		},
		onReachBottom() {
			if (this.loadStatus === 'nomore') return
			this.queryParams.pageNum += 1
			this.getList()
		},
		created() {
			getDicts('biz_product_type').then(res=>{
				
			})
		},
		methods: {
			getList() {
				list(this.queryParams).then(res => {
					this.listFormat(res)
				})
			},
			getMoreList() {
				this.queryParams.pageNum += 1
				this.getList()
			},

			handleToDetail(obj) {
				if (obj.bizType === '入库') {
					this.$tab.navigateTo('./inbound-detail?id=' + obj.id)
				} else if (obj.bizType === '出库') {
					this.$tab.navigateTo('./outbound-detail?id=' + obj.id)
				}
			},
			handleReset(query) {
				this.queryParams = {
					...this.queryParams,
					...query,
					warehouseName: '',
					productName:'',
					pageNum: 1
				}
				this.getList()
			},
			handleSearch(query) {
				this.queryParams = {
					...this.queryParams,
					...query,
					pageNum: 1
				}
				this.getList()
			},
		}
	}
</script>

<style lang="scss" scoped>
	.text-width {
		width: 45px;
		display: inline-block;
	}
</style>